package com.doudoukeji.service.Http;

import android.content.Context;
import android.content.Intent;

import com.doudoukeji.service.Activity.ConstantValue;
import com.doudoukeji.service.Bean.Token;
import com.sanhai.android.mvp.IBaseView;
import com.sanhai.android.service.http.FastHttpResponseHandler;
import com.sanhai.android.service.http.Response;

/**
 * Created by boy on 2016/3/23.
 */
public  abstract class MyHttpResponseHandler extends FastHttpResponseHandler {
    public Context mcontext;
    private IBaseView view = null;

    public MyHttpResponseHandler() {
    }

    public MyHttpResponseHandler(IBaseView view) {
        this.view = view;
    }

    @Override
    public void onResponse(Response response) {


        if (ConstantValue.OGTOLOGINCODE.equals(response.getStatus())) {
            mcontext = Token.getMcontext();
            logOut(response.getStatus());
        }
        this.onMyResponse(response);
    }

    public void logOut(String status) {
        if (ConstantValue.OGTOLOGINCODE.equals(status)) {
            String mess = "发现您的帐号在其它设备上登录,请重新登录";
            String title = "异地登录";

            Intent intent = new Intent();
            intent.setAction(ConstantValue.goToLogin);
            intent.putExtra("message", mess);
            intent.putExtra("msgType", status);
            mcontext.sendBroadcast(intent);
        }
    }

    public abstract void onMyResponse(Response response);
}
